package com.lkd.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lkd.dto.VmTypeDTO;
import com.lkd.entity.VmType;
import com.lkd.mapper.VmTypeMapper;
import com.lkd.result.TableInfo;
import com.lkd.service.VmTypeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Z.lx
 * @Date: 2025/8/17 16:21
 * @Description:
 **/
@Service
public class VmTypeServiceImpl implements VmTypeService{
    @Autowired
    private VmTypeMapper vmTypeMapper;
    public TableInfo<VmType> list(VmTypeDTO vmTypeDTO) {
        PageHelper.startPage(vmTypeDTO.getPageIndex(),vmTypeDTO.getPageSize());
        List<VmType> vmTypeList = vmTypeMapper.list(vmTypeDTO.getName());
        Page<VmType> page = (Page<VmType>) vmTypeList;
        return new TableInfo<>(vmTypeDTO.getPageIndex(),vmTypeDTO.getPageSize(),page.getPages(),page.getTotal(),page.getResult());
    }

    @Override
    public boolean add(VmTypeDTO vmTypeDTO) {
        return vmTypeMapper.insert(vmTypeDTO)>0;
    }

    @Override
    public boolean update(VmTypeDTO vmTypeDTO) {
        VmType vmType = new VmType();
        BeanUtils.copyProperties(vmTypeDTO,vmType);
        return vmTypeMapper.updateVmType(vmType);
    }

    @Override
    public boolean delete(String vmTypeId) {
        return vmTypeMapper.deleteById(vmTypeId)>0;
    }

    @Override
    public VmType getById(String vmTypeId) {
        return vmTypeMapper.selectById(vmTypeId);
    }
}
